#include "JSONArray.h"
#include "JSONObject.h"
#include "JSONString.h"

JSONArray::JSONArray(void)
{
}

JSONArray::~JSONArray(void)
{
	JSONArrayDATA::iterator pItr;
	for(pItr = m_data.begin(); pItr != m_data.end(); ++pItr){
		delete *pItr;
	}
}

void JSONArray::setData(std::istream &is)
{
	JSONValue *pValue = 0;
	char c = is.get();

	while(c != ']'){
		if(c == ','){
			c = is.get();
		}
		switch(c){
			case '{': pValue = new JSONObject;
				       pValue->setData(is);
					   break;
			case '[': pValue = new JSONArray;
				       pValue->setData(is);
					   break;
			default : is.putback(c);
				      pValue = new JSONString;
				      pValue->setData(is);
		}

		m_data.push_back(pValue);

		c = is.get();
	}
}